<?php
$db = mysql_connect('localhost','root','') or die ('Problem connecting to DataBase');
mysql_query("SET NAMES 'UTF8'");
mysql_select_db('userdb_35872_2',$db);
//$keywords = "  nm 011050  ";
$keywordsOrigin = " 011050 ";
$keywords = strtoupper($keywordsOrigin);
$keywords = str_replace(" ","",$keywords);
$keywords = str_replace("-","",$keywords);
$keywords = str_replace("_","",$keywords);
if(strncmp($keywords, 'GI', 2)==0)
{
    $keywords= str_replace("GI", "GI:", $keywords);
}elseif (strncmp($keywords, 'BC', 2)==0 or is_numeric($keywords)) {
    
}else
{
    $letterword = substr($keywords, 0, 2);
    $keywords=  str_replace($letterword, $letterword.'_', $keywords);
}
echo"
    <div id='srchResultTitle'>Search Results by Accession Number: <span style='color:#F00; font-size:20px; font-weight:bold; font-family:sans-serif;'>".$keywordsOrigin."</span></div>
      <div id='homepage_block'>
            <div id='homepage_line1'>";
//Search from database
$res_count = 0;
$srchdb = array("prodsirna","prodlenti","prodadenovirus","prodProteinVector","prodORFVector","prodprotein","prodlysates");
foreach ($srchdb as $val){
    switch ($val){
        case "prodsirna":
            $grpName = "siRNA Lentiviruses";
            $links = "/searchByAccessionNo/siRNALentivirus.php?keywords=$keywords";
            $condi = "where AccessionNumber like '%$keywords%'";
            break;
        case "prodlenti":
            $grpName = "Lentiviral Vectors";
            $links = "/searchByAccessionNo/premadeLentivirus.php?keywords=$keywords";
            $condi = "where AccessionNumber like '%$keywords%' or AlternativeAccession like '%$keywords%'";
            break;
        case "prodadenovirus"://dbno=4
            $grpName = "Premade Adenoviruses";
            $links = "/searchByAccessionNo/premadeAdenovirus.php?keywords=$keywords";
            $condi = "where AccessionNumber like '%$keywords%' or OtherAccession like '%$keywords%'";
            break;
        case "prodProteinVector"://dbno=53=========================
            $grpName = "Protein Vectors";
            $links = "/searchByAccessionNo/premadeProteinVectors.php?keywords=$keywords";
            $condi = "where AccessionNumber like '%$keywords%'";
            break;
        case "prodORFVector"://dbno=54=========================
            $grpName = "ORF cDNA Vectors";
            $links = "/searchByAccessionNo/premadeORFVectors.php?keywords=$keywords";
            $condi = "where AccessionNumber like '%$keywords%'";
            break;
        case "prodprotein"://dbno=32
            $grpName = "Recombinant Proteins";
            $links = "/searchByAccessionNo/iPSC-RP.php?keywords=$keywords";
            $condi = "where AccessionNumber like '%$keywords%'";
            break;
        case "prodlysates"://dbno=12======================
            $grpName = "Cell Lysate";
            $links = "/searchByAccessionNo/CellLysate.php?keywords=$keywords";
            $condi = "where accessionNo like '%$keywords%'";
            break;
        

    }
    $srch = "select sn from `$val` $condi"; 
    $srchRes = mysql_query($srch,$db);
    $srchrows = mysql_num_rows ($srchRes);
    /*$srch = "select count(sn) AS NumberOfQuery from `$val` $condi"; 
    $srchRes = mysql_query($srch,$db);
    $srch_r = mysql_fetch_array($srchRes);
    $srchrows = $srch_r['NumberOfQuery'];*/
    if ($srchrows == 0){
            continue;
    }elseif ($srchrows == 1){
            $res_count ++;
            $alink = "<a href='$links'>$srchrows</a>&nbsp;<span style='font-size:10px; color:#000; text-decoration:none;'>match</span>";
    }elseif ($srchrows > 0){
            $res_count ++;
            $alink = "<a href='$links'>$srchrows</a>&nbsp;<span style='font-size:10px; color:#000; text-decoration:none;'>matches</span>";
    }

    //$srch_r = mysql_fetch_array($srchRes);
    echo "
            <div style='background-color:#e69e50;float:left; display:inline;'>
              <div style='margin:2px; width:152px; height:120px; border-left:2px solid #FFF; border-top:2px solid #FFF; border-right:2px solid #ad9378; border-bottom:2px solid #ad9378;  background-color:#e6f8eb;'>
                    <div style='height:auto; margin:5px 10px 5px 5px; font-size:12px; color:#000; font-weight:bold; text-align:center;'>$grpName</div>
                    <div style='padding-top:15px; height:55px; margin:5px 10px 5px 5px; font-size:40px; color:#00f; text-align:center; line-height:50px;'>$alink</div>
              </div>
            </div>
    ";
    }

    if ($res_count == 0){
            echo "
                    <div style='background-color:#e69e50;float:left; display:inline;'>
                      <div style='margin:2px; width:152px; height:120px; border-left:2px solid #FFF; border-top:2px solid #FFF; border-right:2px solid #ad9378; border-bottom:2px solid #ad9378;  background-color:#e6f8eb;'>
                            <div style='height:auto; margin:5px 10px 5px 5px; font-size:12px; color:#000; font-weight:bold; text-align:center;'>No matched products found.</div>
                      </div>
                    </div>
            ";
    }

    echo "
            </div>
        </div>";

            
?>
